using System;
using System.Drawing;

namespace Diversity.Robotics.Navigation
{
    /// Pretty stupid ... this could be a Point

    /// <summary>
    /// An x,y representation of a landmark.
    /// </summary>
    public class Landmark : ICloneable
    {
        private double _x;
        private double _y;

        /// <summary>
        /// Creates a landmark.
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        public Landmark(double x, double y)
        {
            _x = x;
            _y = y;
        }

        /// <summary>
        /// The real X coordinate.
        /// </summary>
        public double X
        {
            get { return _x; }
            set { _x = value; }
        }

        /// <summary>
        /// The real Y coordinate.
        /// </summary>
        public double Y
        {
            get { return _y; }
            set { _y = value; }
        }

     
        /// <summary>
        /// Creates a copy of the Landmark.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return new Landmark(_x, _y);
        }

        /// <summary>
        /// Converts the Landmark to a string representation
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return "Landmark (x: " + _x + " ,y: " + _y + ")";
        }

        /// <summary>
        /// Creates an int point structure for drawing.
        /// </summary>
        /// <returns>The landmark expressed as a point.</returns>
        public Point ToPoint()
        {
            return new Point((int)Math.Round(_x), (int)Math.Round(_y));
        }

        /// <summary>
        /// Finds the distance between two landmarks.
        /// </summary>
        /// <param name="landmark">The other landmark.</param>
        /// <returns>The Euclidian distance.</returns>
        public double GetDistanceTo(Landmark landmark)
        {
            return Math.Sqrt(Math.Pow(_x - landmark.X, 2) + Math.Pow(_y - landmark.Y, 2));
        }

        /// <summary>
        /// Finds the angle to the other landmark.
        /// </summary>
        /// <param name="landmark">The other landmark.</param>
        /// <returns>The angle.</returns>
        public double GetAngleTo(Landmark landmark)
        {
            return Math.Atan2(landmark.Y - _y, landmark.X - _x);
        }
    }
}
